﻿using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace nhCore
{
    public class Util
    {
        /// <summary>
        /// 检查数组序号是否存在，有则取指定序号的值，没有则返回默认值
        /// </summary>
        /// <typeparam name="T">类型数组</typeparam>
        /// <param name="array">数组</param>
        /// <param name="index">序号</param>
        /// <returns>返回指定序号的值</returns>
        public static T GetArrayElements<T>(IList<T> array, int index)
        {
            return array.Count > index ? array[index] : default;
        }

        /// <summary>
        /// 检查字典key是否存在，有则取指定Key的值，没有则返回默认值
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="dictionary"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static TValue GetDictionaryElements<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key)
        {
            return dictionary.ContainsKey(key) ? dictionary[key] : default;
        }
    }
}